package api

import (
	"gateway-api/basic/config"
	__ "gateway-api/basic/proto"
	"gateway-api/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func OrderCreate(c *gin.Context) {
	var param request.OrderCreate
	if err := c.ShouldBind(&param); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  "参数错误",
		})
		return
	}
	r, err := config.UserCline.OrderCreate(c, &__.OrderCreateReq{
		PackageId:      param.PackageId,
		UserId:         param.UserId,
		ReserveStockId: param.ReserveStockId,
		Stock:          param.Stock,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"mes":  "订单创建成功",
		"data": r,
	})
	return
}

func OrderList(c *gin.Context) {
	var param request.OrderList
	if err := c.ShouldBind(&param); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  "参数错误",
		})
		return
	}
	r, err := config.UserCline.OrderList(c, &__.OrderListReq{
		Page:     param.Page,
		PageSize: param.PageSize,
		Status:   param.Status,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"mes":  err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"mes":  "订单展示成功",
		"data": r,
	})
	return
}
